package com.bifang.common.util;

import cn.hutool.core.bean.BeanUtil;
import java.util.List;
import java.util.Map;
import org.springframework.util.CollectionUtils;

public class UpdateBeanUtil {
    public static void updateBean(Object fromBean, Object newBean, List<String> ignoreList) {
        if (fromBean == null) {
            return;
        }
        Map<String, Object> fromMap = BeanUtil.beanToMap(fromBean, false, true);
        if (!CollectionUtils.isEmpty(ignoreList)) {
            for (String str : ignoreList) {
                fromMap.remove(str);
            }
        }
        UpdateBeanUtil.updateMapToBean(fromMap, newBean);
    }

    public static void updateBean(Object fromBean, Object newBean) {
        if (fromBean == null) {
            return;
        }
        Map<String, Object> oldMap = BeanUtil.beanToMap(fromBean, false, true);

        oldMap.remove("authStatus");
        oldMap.remove("authRemarks");
        oldMap.remove("authUserId");
        oldMap.remove("authTime");
        oldMap.remove("createName");
        oldMap.remove("createTime");
        oldMap.remove("updateName");
        oldMap.remove("updateTime");
        oldMap.remove("del");
        UpdateBeanUtil.updateMapToBean(oldMap, newBean);
    }

    public static void updateMapToBean(Map<String, Object> fromMap, Object newBean) {
        if (CollectionUtils.isEmpty(fromMap)) {
            return;
        }
        BeanUtil.fillBeanWithMap(fromMap, newBean, true);
    }
}
